package com.xm.xmapp.http;

import android.app.Activity;
import android.content.Intent;

import com.alibaba.fastjson.JSON;
import com.android.volley.VolleyError;
import com.xm.xmapp.AuthorizeActivity;
import com.xm.xmapp.AuthorizeVerifyActivity;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.myinterface.BaseDataInterFace;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.request.bean.Get_user_information_statusRequest;
import com.xm.xmapp.response.bean.ResponseUserBean;
import com.xm.xmapp.response.bean.UserInformationStatusBean;

public class ChangDataTools {

	public static void Get_user_information_statusRequest(final ResponseUserBean userBean, final Activity activity,
			final BaseDataInterFace listener) {

		if (userBean != null && userBean.check_data_status == 1)
			listener.success();
		else {
			Get_user_information_statusRequest requestBean = new Get_user_information_statusRequest();
			MyAppcation.getMyAppcation().getPostData(activity, requestBean, new GetDataInterFace<String>() {

				@Override
				public void onResponse(String response) {
					Intent intent;
					UserInformationStatusBean statusBean = JSON.parseObject(response, UserInformationStatusBean.class);
					switch (statusBean.user_information_status) {
					case -1:
						intent = new Intent(MyAppcation.getMyAppcation(), AuthorizeActivity.class);
						intent.putExtra("bean", statusBean);
						activity.startActivity(intent);
						listener.fail();
						break;
					case 0:
						intent = new Intent(MyAppcation.getMyAppcation(), AuthorizeActivity.class);
						intent.putExtra("bean", statusBean);
						activity.startActivity(intent);
						listener.fail();
						break;
					case 1:
						if (userBean != null) {
							userBean.check_data_status = 1;
							MyAppcation.getMyAppcation().saveUserBean(userBean);
						}

						break;
					case 2:
						intent = new Intent(MyAppcation.getMyAppcation(), AuthorizeVerifyActivity.class);
						activity.startActivity(intent);
						listener.fail();
						break;
					default:
						listener.fail();
						break;
					}

				}
			}, new DisssmissInterFace() {

				@Override
				public void putError(VolleyError error) {
					listener.fail();
				}
			});
		}

	}
}
